package com.haohan.jingyuan.util;

import java.util.UUID;

/**
 * @ClassName UuidUtil
 * @Description
 * @Author hexijun
 * @Time 2025/10/18 23:06
 * @Version 1.0
 */
public class UuidUtil {

    private final static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


    /**
     * 随机生成id
     *
     * @param length
     * @return
     */
    public static String generateId(int length) {
        return generateId("", length);
    }

    /**
     * 随机生成id
     *
     * @param type
     * @return
     */
    public static String generateId(String type, int length) {
        StringBuilder userId = new StringBuilder();
        // 生成10位随机字符
        for (int i = 0; i < length; i++) {
            int index = (int) (Math.random() * chars.length());
            userId.append(chars.charAt(index));
        }
        return type + userId.toString();
    }

    public static String uuid() {
        return System.currentTimeMillis() + UUID.randomUUID().toString().replaceAll("-", "");
    }

}
